package com.choosefine.it.payment.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.payment.model.TradeFlow;
import com.choosefine.it.payment.service.TradeFlowService;

@Api(value="交易流水")
@RestController
@RequestMapping("/tradeFlow")
public class TradeFlowController extends BaseController {

	@Autowired
	TradeFlowService tradeFlowService;
	
	@ApiOperation("新增交易流水")
	@RequestMapping(value="/addTradeFlow",method=RequestMethod.POST)
	public String addTradeFlow(@RequestBody TradeFlow tradeflow){
		String result=null;
		Integer isSuccess = tradeFlowService.insert(tradeflow);
		
		if(isSuccess.intValue()>0){
			result= responseSuccess(isSuccess, ResultCode.SUCCESS,ResultCode.MSG_SUCCESS);
			return result;
		}else{
			result= responseFail(ResultCode.FAILED,ResultCode.MSG_PARAMS_NULL);
			return result;
		}
	}
	
	@ApiOperation("修改交易流水")
	@RequestMapping(value="/updateTradeFlow",method=RequestMethod.PUT)
	public String updateTradeFlow(@RequestBody TradeFlow tradeflow){
		String result=null;
		Integer isSuccess = tradeFlowService.update(tradeflow);
		if(isSuccess.intValue()>0){
			result= responseSuccess(isSuccess, ResultCode.SUCCESS,ResultCode.MSG_SUCCESS);
			return result;
		}else{
			result= responseFail(ResultCode.FAILED,ResultCode.MSG_PARAMS_NULL);
			return result;
		}
	}
	
	@ApiOperation("修改交易流水单状态")
	@RequestMapping(value="/updateStatus",method=RequestMethod.PUT)
	public String updateStatus(@RequestBody Integer status ){
		String result=null;
		TradeFlow tradeflow =new TradeFlow();
		tradeflow.setStatus(status);
		tradeflow.setUtime(new Date().getTime());
		Integer isSuccess = tradeFlowService.update(tradeflow);
		if(isSuccess.intValue()>0){
			result= responseSuccess(isSuccess, ResultCode.SUCCESS,ResultCode.MSG_SUCCESS);
			return result;
		}else{
			result= responseFail(ResultCode.FAILED,ResultCode.MSG_PARAMS_NULL);
			return result;
		}
	}
	
	@ApiOperation("条件查询交易流水")
	@RequestMapping(value="/getTradeFlowByCondition",method=RequestMethod.GET)
	public String getTradeFlowByCondition(@RequestBody TradeFlow tradeflow ){
		String result=null;
		List<TradeFlow> list = tradeFlowService.findByCondition(tradeflow);
		if(CollectionUtils.isNotEmpty(list)){
			result = responseSuccess(list);
			return result;
		}else{
			result= responseFail(ResultCode.FAILED,ResultCode.MSG_PARAMS_NULL);
			return result;
		}
	}
	

}
